﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ShapeDraw.Model;
 
namespace ShapeDraw.Control
{
    public partial class StandChild : ChildWindow
    {
        public StandChild()
        {
            InitializeComponent();
            //this.Title = "";
            InitData(); 
        }

        private void InitData()
        {
            //throw new NotImplementedException();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            Service.CommServiceClient client = new Service.CommServiceClient();
            string hostUri = App.Current.Host.Source.AbsoluteUri;
            hostUri = hostUri.Substring(0, hostUri.IndexOf("/ClientBin"));
            string svcUri = hostUri + "/WebService/CommService.svc";
            client.Endpoint.Address = new EndpointAddress(svcUri);
            Service.StandModel mdl = new Service.StandModel();
            mdl.StandNum = StandNum.Text;
            mdl.DisplayNum = DisplayNum.Text;
            mdl.ClassId = Convert.ToInt32(ClassId.SelectedValue);
            mdl.StandLen = Convert.ToInt32( StandLen.Text);
            mdl.StandWidth =Convert.ToInt32( StandWidth.Text);
            mdl.StandSize =Convert.ToInt32(  StandSize.Text);
            mdl.DisplayMsg = DisplayMsg.Text;
            mdl.ColorTpId = Convert.ToInt32(ColorTpId.SelectedValue);
           
            client.SaveStandAsync(mdl);
            client.SaveStandCompleted += new EventHandler<Service.SaveStandCompletedEventArgs>(SaveComplete);
            
          
        }

        private void SaveComplete(object sender, Service.SaveStandCompletedEventArgs e)
        {
            
            if (e.Result == 1)
            {
                MessageWin win = new MessageWin("恭喜你数据保存成功!");
                win.Show();
               
            }
            else {
                MessageWin win = new MessageWin("对不起数据保存失败，请联系管理员！");
                win.Show();
            }
           
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();   
        }
    }
}

